package com.libcommon.ext

import com.blankj.utilcode.util.ThreadUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob

/**
 * CreateBy:Joker
 * CreateTime:2023/12/9 18:31
 * description：
 */

fun workIO(ioRun: () -> Unit) {
    ThreadUtils.getIoPool().execute { ioRun.invoke() }
}

fun workUI(uiRun: () -> Unit) {
    ThreadUtils.runOnUiThread { uiRun.invoke() }
}

fun workIOWithCallBack(ioRun: () -> Unit, uiRun: () -> Unit) {
    workIO {
        ioRun.invoke()
        workUI { uiRun.invoke() }
    }
}

val sGlobalMainScope by lazy {
    CoroutineScope(SupervisorJob() + Dispatchers.Main)
}

val sGlobalIOScope by lazy {
    CoroutineScope(SupervisorJob() + Dispatchers.IO)
}